package com.jrx.anytxn.investor.mapper.ext;

import com.jrx.anytxn.investor.entity.AmRepaymentPlanInvestorInfo;
import com.jrx.anytxn.investor.mapper.base.AmRepaymentPlanInvestorInfoMapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * 还款计划（出资方）扩展
 *
 * @author liuyang
 * @date 2020-05-20
 */
public interface ExtAmRepaymentPlanInvestorInfoMapper extends AmRepaymentPlanInvestorInfoMapper {

    /**
     * 批量插入还款计划
     *
     * @param repaymentPlanInvestorInfoList 还款计划列表
     * @return int 插入的条数
     * @author liuyang
     * @date 2020-05-20
     */
    int batchInsertRepaymentPlanInfoList(List<AmRepaymentPlanInvestorInfo> repaymentPlanInvestorInfoList);


    /**
     * 根据资金方贷款id，状态，客户id查询还款计划
     *
     * @param investorLoanId 资金方贷款id
     * @param status         状态
     * @param customerId     客户id
     * @param tenantId       租户id
     * @return List<AmRepaymentPlanInvestorInfo> 还款计划
     * @author liuyang
     * @date 2020-05-20
     */
    List<AmRepaymentPlanInvestorInfo> selectByInvestorLoanIdAndStatus(@Param(value = "investorLoanId") String investorLoanId,
                                                                      @Param(value = "statusList") List<String> status,
                                                                      @Param(value = "customerId") String customerId,
                                                                      @Param(value = "tenantId") String tenantId);

    /**
     * 批量更新还款计划（作用于批量）
     *
     * @param amRepaymentPlanInfos 还款计划
     * @return int 更新的条数
     * @author liuyang
     * @date 2020-05-25
     */
    int batchUpdatePlanForBatch(List<AmRepaymentPlanInvestorInfo> amRepaymentPlanInfos);

    /**
     * 通过贷款ID及状态(数组传值)获取贷款计划
     *
     * @param investorLoanId 出资方贷款id
     * @param status         状态数组
     * @param customerId     客户id
     * @param tenantId       租户id
     * @return List<AmRepaymentPlanInvestorInfo> 还款计划
     * @author liuyang
     * @date 2020-05-25
     */
    List<AmRepaymentPlanInvestorInfo> selectRepaymentPlanInfoListByInvestorLoanIdAndStatus(@Param(value = "investorLoanId") String investorLoanId,
                                                                                           @Param(value = "statusArrays") String[] status,
                                                                                           @Param(value = "customerId") String customerId,
                                                                                           @Param("tenantId") String tenantId);

    /**
     * 根据贷款id客户id查询还款计划
     *
     * @param loanId     贷款id
     * @param status     状态
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return List<AmRepaymentPlanInvestorInfo> 还款计划
     * @author liuyang
     * @date 2020-05-20
     */
    List<AmRepaymentPlanInvestorInfo> selectByLoanIdAndStatus(@Param(value = "loanId") String loanId,
                                                              @Param(value = "statusList") List<String> status,
                                                              @Param(value = "customerId") String customerId,
                                                              @Param(value = "tenantId") String tenantId);

    /**
     * 根据期次获取
     *
     * @param customerId
     * @param tenantId
     * @param loanId
     * @param billingTenor
     * @return
     */
    AmRepaymentPlanInvestorInfo selectByLoanIdAndTenor(String customerId, String tenantId, String loanId, int billingTenor);

    /**
     * 根据以下条件查询资金方还款计划信息
     *
     * @param customerId 客户ID
     * @param tenantId   租户ID
     * @param loanId     贷款订单ID
     * @param investorId 资金方ID
     * @return java.util.List<com.jrx.anytxn.investor.entity.AmRepaymentPlanInvestorInfo>
     * @author fan.yang
     * date: 2020/6/23 0023 下午 17:33
     */
    List<AmRepaymentPlanInvestorInfo> selectPlanListByCusIdAndLoanIdAndInveId(@Param("customerId") String customerId, @Param("tenantId") String tenantId, @Param("loanId") String loanId, @Param("investorId") String investorId);

    /**
     * 根据期次获取
     *
     * @param customerId
     * @param tenantId
     * @param investorLoanId
     * @param billingTenor
     * @return
     */
    AmRepaymentPlanInvestorInfo selectByInvestorLoanIdAndTenor(@Param("customerId") String customerId, @Param("tenantId") String tenantId, @Param("investorLoanId") String investorLoanId, @Param("billingTenor") int billingTenor);

    /**
     * 批量更新还款计划（作用于联机交易）
     *
     * @param updatePlanList
     */
    void batchUpdate(List<AmRepaymentPlanInvestorInfo> updatePlanList);

    /**
     * 根据还款计划状态，还款日获取还款计划
     *
     * @param planStatus        还款计划状态
     * @param today             当前系统日期
     * @param lastProcessingDay 上一处理日
     * @return List<AmRepaymentPlanInvestorInfo> 还款计划
     * @author liuyang
     * @date 2020-05-26
     */
    List<AmRepaymentPlanInvestorInfo> selectByStatusAndPaymentDate(@Param(value = "planStatus") String planStatus,
                                                                   @Param(value = "today") Date today,
                                                                   @Param(value = "lastProcessingDay") Date lastProcessingDay);

    /**
     * 根据出资方贷款id、期数、状态、客户id、租户id查询还款计划
     *
     * @param investorLoanId 出资方贷款id
     * @param customerId     客户id
     * @param tenantId       租户id
     * @param billingTenor   期数
     * @param status         状态
     * @return AmRepaymentPlanInvestorInfo 还款计划
     * @author liuyang
     * @date 2020-05-26
     */
    AmRepaymentPlanInvestorInfo selectByInvestorLoanIdAndBillingTenor(@Param(value = "investorLoanId") String investorLoanId,
                                                                      @Param(value = "customerId") String customerId,
                                                                      @Param(value = "tenantId") String tenantId,
                                                                      @Param(value = "billingTenor") Integer billingTenor,
                                                                      @Param(value = "statusList") List<String> status);

    /**
     * 根据客户id，渠道，出资方贷款id，期数查询还款计划
     *
     * @param customerId     客户id
     * @param tenantId       租户id
     * @param channel        渠道
     * @param investorLoanId 出资方贷款id
     * @param billingTenor   期数
     * @return AmRepaymentPlanInvestorInfo 还款计划
     * @author liuyang
     * @date 2020-05-27
     */
    AmRepaymentPlanInvestorInfo selectByInvestorLoanIdAndChannel(@Param("customerId") String customerId, @Param("tenantId") String tenantId,
                                                                 @Param("channel") String channel, @Param("investorLoanId") String investorLoanId,
                                                                 @Param("billingTenor") Integer billingTenor);

    List<AmRepaymentPlanInvestorInfo> selectByInvestorLoanIdNotPlanStatus(@Param("investorLoanId") String investorLoanId,
                                                                          @Param("planStatus") String planStatus);

    /**
     * 通过贷款ID及状态(数组传值)获取贷款计划
     *
     * @param status     状态数组
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return List<AmRepaymentPlanInvestorInfo> 还款计划
     * @author liuyang
     * @date 2020-05-25
     */
    List<AmRepaymentPlanInvestorInfo> findByCust(@Param(value = "statusArrays") String[] status,
                                                 @Param(value = "customerId") String customerId,
                                                 @Param("tenantId") String tenantId);


}
